<?php

namespace App\Http\Controllers\Api;

use App\Audios;
use App\Files;
use App\Http\Services\FileManager;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AudioController extends Controller
{
    public function getAudioUrl($audioId){
        /** @var Audios $thatAudio */
        $thatAudio = Audios::whereId($audioId)->first();
        if(!$thatAudio)
            return url('audio/刘德华+-+恭喜发财+-123.mp3');

        /** @var Files $file */
        $file = Files::whereId($thatAudio->file_id)->first();
        if(!$file)
            return url('audio/刘德华+-+恭喜发财+-123.mp3');

        $audio_url = $file->getLocalPath();

//        return response($audio_url,405)->header('Content-Type',$file->file_ext);
        return \Response::download($audio_url,$thatAudio->audio_name,[],'inline');

    }

}
